import unittest
import handler.Voice
from unittest.mock import patch


class test_Voice(unittest.TestCase):
	@patch('handler.Voice.pyttsx3')
	@patch('handler.Voice.Process')
	def test_on_change_a_say_process_will_be_started(self, mock_process, mock_pyttsx3):
		engine = test_Voice.fake_engine()
		mock_pyttsx3.init.return_value = engine

		process = test_Voice.fake_process()
		mock_process.return_value = process

		voice = self._arrange_voice()

		voice.change_state(None, '.David:Hello world')

		self.assertTrue(process.is_started)

	def _test_speak_a_line(self):
		voice = self._arrange_voice()

		voice.change_state(None, '.David:Hello world')

	def _arrange_voice(self):
		content = {
			'name': 'voice',
			'handler': 'voice',
			'actors': ['David', 'Hazel'],
			'queue': 3,
			'say_rate': 190,
			'say_volume': 1.0,
			'shout_rate': 260,
			'shout_volume': 1.0
		}

		return handler.Voice.Voice(content)

	class fake_process():
		def __init__(self):
			self.is_started = False

		def start(self):
			self.is_started = True

	class fake_engine():
		def getProperty(self, name):
			return [test_Voice.fake_voice('David'), test_Voice.fake_voice('Hazel')]

	class fake_voice():
		def __init__(self, name):
			self.id = 'id_' + name
			self.name = name
